def generateSqlForAseetOldData():
    file_dir = '/Users/jiufenshiren/Downloads/普聚和长帆存量数据.csv'
    sql_format = "INSERT INTO `jixint_account_core`.account_maintenance_info (contract_id, product_code, maintenance_type, store_id, loan_amount, inst_code, inst_name) VALUES ('{}', 'fm_jx', '2', '{}', {},  '{}', '{}');"
    sql_list = []

    count = 0
    with open(file_dir, 'rb') as f:
        while True:
            count += 1
            line = f.readline()
            if not line:
                break
            if count == 1:
                print(line.decode().strip())
                continue
            line = line.decode().strip()
            line_split = line.split(',')
            contract_id = line_split[0]
            loan_amount = int(line_split[1]) * 100
            inst_name = line_split[4]

            if inst_name == '普聚一':
                inst_code = 'PUJU1'
                store_id = '6086'
            elif inst_name == '普聚二':
                inst_code = 'PUJU2'
                store_id = '6088'
            elif inst_name == '普聚三':
                inst_code = 'PUJU3'
                store_id = '6092'
            elif inst_name == '长帆一':
                inst_code = 'CHANGFAN1'
                store_id = '6097'
            elif inst_name == '长帆二':
                inst_code = 'CHANGFAN2'
                store_id = '6099'
            elif inst_name == '长帆三':
                inst_code = 'CHANGFAN3'
                store_id = '6098'
            else:
                continue

            sql = sql_format.format(contract_id, store_id, loan_amount, inst_code, inst_name)
            sql_list.append(sql)
    print(count)
    return sql_list


def sql_list_to_file(sql_list):
    with open('old_Data.sql', 'w') as f:
        for sql in sql_list:
            f.write(sql + '\n')


if __name__ == '__main__':
    data = generateSqlForAseetOldData()
    print(len(data))
    sql_list_to_file(data)
